    
#include <gio/gio.h>
#include <stdio.h>
#include <error.h>
#include <sys/ipc.h>
#include <sys/shm.h>

#define SHM_SIZE 100
#define SHM_KEY 1111
int main(int argc, char **argv)
{
  int shmid, i = 0;
  key_t key = SHM_KEY;

  /* 创建共享内存区 */
  if ((shmid = shmget(key, SHM_SIZE, IPC_CREAT | 0666)) < 0) {
      perror("shmget");
      exit(1);
  }

  /* 连接到共享内存区 */
  char *shm_ptr;
  if ((shm_ptr = shmat(shmid, NULL, 0)) == (char *) -1) {
      perror("shmat");
      exit(1);
  }

  printf("\n");
  for (i = 0; i < SHM_SIZE; i++) {
    printf("%02x ", shm_ptr[i]);
  }
  printf("\n");

  /* 断开与共享内存区的连接 */
  if (shmdt(shm_ptr) == -1) {
      perror("shmdt");
      exit(1);
  }
}
